package net.zjitc.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.zjitc.common.ResponseResult;
import net.zjitc.entity.Jobhunting;
import net.zjitc.entity.VO.JobHuntingyonghuVo;
import net.zjitc.service.IJobhuntingService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

/**
 * @auther 郭梦婷
 * @create 2022-05-10 14:22:24
 * @describe 前端控制器
 */
@CrossOrigin
@RestController
@Api(tags = "求职者管理")
public class JobhuntingController {
    @Reference
    private IJobhuntingService jobhuntingService;

    ResponseResult result=new ResponseResult();

    @ApiOperation("获取所有求职者信息")
    @GetMapping("jobhunting")
    public ResponseResult getJobhunting(@RequestParam(required = false,value ="querystring" ) String querystring,
                                     @RequestParam(required = true ,value = "pagenum") Integer pagenum,
                                     @RequestParam(required = true,value = "pagesize") Integer pagesize){
        Page<JobHuntingyonghuVo> jobhunting=jobhuntingService.getJobhuntings(querystring,pagenum,pagesize);
        if (jobhunting.getTotal()>0){
            result.setSuccess("获取求职者成功",jobhunting);
        }else {
            result.setError("获取求职者失败");
        }
        return result;
    }
    @ApiOperation("根据id查找应聘信息")
    @GetMapping("jobhunting/{id}")
    public ResponseResult getJobhuntingById(@PathVariable("id") Integer id){
        JobHuntingyonghuVo jobhunting = jobhuntingService.selectById(id);
        if (jobhunting!=null){
            result.setSuccess("获取求职者成功",jobhunting);
        }else {
            result.setError("获取求职者失败");
        }
        return result;
    }

    @ApiOperation("修改应聘信息")
    @PutMapping("jobhunting/{id}")
    public ResponseResult UpdateJobhunting(@RequestBody Jobhunting jobhunting, @PathVariable("id") int id){
        jobhunting.setId(id);
        boolean update = jobhuntingService.updateById(jobhunting);
        if (update){
            result.setSuccess("修改应聘信息成功",update);
        }else {
            result.setError("修改应聘信息失败");
        }
        return result;
    }
    @ApiOperation("删除应聘信息")
    @DeleteMapping("jobhunting/{id}")
    public ResponseResult DeleteJobhunting(@PathVariable("id") int id){

        int delete= jobhuntingService.deleteById(id);
        if (delete!=0){
            result.setSuccess("删除应聘信息");
        }else {
            result.setError("删除应聘信息");
        }
        return result;
    }


}

